package javabook;

import com.gule.gl.leetcode.editor.cn.definition.TreeNode;

import java.util.Objects;

/**
 * @Auther: gl
 * @Date: 2020/2/12 12:42
 * @Description:
 */
public class TwoTreeEqual {

    /**
     * 判断两棵树是否相等
     *
     * @return
     */
    boolean judgeTwoTreeIsEqual(TreeNode tree1, TreeNode tree2) {
        if (Objects.isNull(tree1) && Objects.isNull(tree2)) {
            return true;
        }
        if (Objects.isNull(tree1) || Objects.isNull(tree2)) {
            return false;
        }
        if (tree1.val == tree2.val) {
            return judgeTwoTreeIsEqual(tree1.left, tree2.left) &&
                    judgeTwoTreeIsEqual(tree1.right, tree2.right);
        } else {
            return false;
        }

    }
}
